package cn.ito.zjgsu.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.ito.zjgsu.domain.Person;
import cn.ito.zjgsu.domain.PersonExample;
import cn.ito.zjgsu.domain.wrapper.PersonWrapper;
import cn.ito.zjgsu.mapping.PersonMapper;
import cn.ito.zjgsu.service.PersonService;
@Service
@Transactional
public class PersonServiceImpl implements PersonService{
	@Resource
	private PersonMapper personMapper;

	@Override
	public PersonWrapper getPersonWrapperById(Integer pid) {
		if(null != pid){
			Person p = getPersonById(pid);
			PersonWrapper pw = wrap(p);
			return pw;
		}else{
			return new PersonWrapper();
		}
		
		
	}

	
	
	public Person getPersonById(Integer pid) {
		PersonExample personExample = new PersonExample();
		personExample.or().andPersonIdEqualTo(pid).andPersonDeleteTagsEqualTo(PersonWrapper.PERSON_EXIST_FLAG);
		return personMapper.selectByExample(personExample).get(0);
	}
	
	private PersonWrapper wrap(Person p) {
		PersonWrapper pw = new PersonWrapper(p);
		return pw;
	}



	@Override
	public List<Person> queryPidsByPidssandKey(Integer[] staffIds, String key) {
		if(null != staffIds){
			return personMapper.queryPidsByPidssandKey(staffIds,key);
		}else{
			return null;
		}
		
	}


	public List<Person> queryAllPerson() {
		PersonExample personExample = new PersonExample();
		personExample.or().andPersonDeleteTagsEqualTo(Person.PERSON_EXIST_FLAG);
		return personMapper.selectByExample(personExample);
	}




	
	
}
